home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / construc / DRBOBSYS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-05  |  2.0 KB  |  88 lines

  1. unit DrBobSys;
  2. { a special unit to circumvent SysUtils and get smaller executables }
  3. interface
  4.  
  5.   function StrPas(Str: PChar): String;
  6.  
  7.   function StrLen(Str: PChar): Cardinal;
  8.  
  9.   function StrToInt(const Str: string): Integer;
  10.  
  11.   function UpperCase(const Str: ShortString): ShortString;
  12.  
  13.   function LowerCase(const Str: ShortString): ShortString;
  14.  
  15. { WINDOWS APIs }
  16.  
  17.   function GetCommandLine: PChar; stdcall;
  18.   function GetEnvironmentStrings: PChar; stdcall;
  19.   function GetUserName(lpBuffer: PChar; var nSize: Integer): Boolean; stdcall;
  20.  
  21. var
  22.   StartTime: LongInt = 0;
  23.  
  24.   function timeGetTime: LongInt; stdcall;
  25.  
  26. implementation
  27.  
  28.   function StrPas(Str: PChar): String;
  29.   begin
  30.     Result := Str;
  31.   end;
  32.  
  33.   function StrLen(Str: PChar): Cardinal; assembler;
  34.   asm
  35.     MOV   EDX,EDI
  36.     MOV   EDI,EAX
  37.     MOV   ECX,0FFFFFFFFH
  38.     XOR   AL,AL
  39.     REPNE SCASB
  40.     MOV   EAX,0FFFFFFFEH
  41.     SUB   EAX,ECX
  42.     MOV   EDI,EDX
  43.   end;
  44.  
  45.   function StrToInt(const Str: string): Integer;
  46.   var
  47.     E: Integer;
  48.   begin
  49.     Val(Str, Result, E);
  50.     if E <> 0 then Result := 0
  51.   end;
  52.  
  53.   function UpperCase(const Str: ShortString): ShortString;
  54.   var
  55.     len: Byte absolute Str;
  56.     i: Integer;
  57.   begin
  58.     Result[0] := Str[0];
  59.     for i:=1 to len do
  60.     begin
  61.       Result[i] := Str[i];
  62.       if (Str[i] in ['a'..'z']) then Dec(Result[i],32)
  63.     end
  64.   end;
  65.  
  66.   function LowerCase(const Str: ShortString): ShortString;
  67.   var
  68.     len: Byte absolute Str;
  69.     i: Integer;
  70.   begin
  71.     Result[0] := Str[0];
  72.     for i:=1 to len do
  73.     begin
  74.       Result[i] := Str[i];
  75.       if (Str[i] in ['A'..'Z']) then Inc(Result[i],32)
  76.     end
  77.   end;
  78.  
  79.   function timeGetTime;
  80.            external 'winmm.dll' name 'timeGetTime';
  81.   function GetEnvironmentStrings;
  82.            external 'kernel32.dll' name 'GetEnvironmentStringsA';
  83.   function GetCommandLine;
  84.            external 'kernel32.dll' name 'GetCommandLineA';
  85.   function GetUserName;
  86.            external 'advapi32.dll' name 'GetUserNameA';
  87. end.
  88.